/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#include "Fps.h"
#include <limits>
#include <cstdlib>

namespace liba
{

Fps::Fps(double interval)
:	interval( interval ),
	fps( 1 ),
	time( 0 )
{}

Fps::~Fps()
{}

double Fps::get_fps()const
{
	return fps;
}

void Fps::record(double delta_time)
{
	time += delta_time;
	records.push_back( time );

	while( records.front() + interval < time )
		records.pop_front();

	double dt = time - records.front();
	fps = (abs(dt) < std::numeric_limits<double>::epsilon()) ? 1 : records.size() / dt;
}


} // namespace liba

